package com.coreservlets.jsf.ss06;

import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.model.SelectItem;

@ManagedBean
public class TrainingForm 
{
	private String emailAddress;
	
	private String favoriteLanguage = LanguageUtils.findMostPopularLanguage( 0 );
	
	private String secondFavoriteLanguage = LanguageUtils.findMostPopularLanguage( 1 );
	
	private boolean isExpert = true;
	
	private boolean isLiar = false;
	
	private List< String > languagesToStudy;

	public String getEmailAddress() 
	{
		return( emailAddress );
	}

	public void setEmailAddress(String emailAddress)
	{
		this.emailAddress = emailAddress;
		
		if( this.emailAddress.isEmpty() )
		{
			this.emailAddress = emailAddress;
		}
	}

	public String getFavoriteLanguage()
	{
		return( favoriteLanguage );
	}

	public void setFavoriteLanguage(String favoriteLanguage) 
	{
		this.favoriteLanguage = favoriteLanguage;
	}

	public String getSecondFavoriteLanguage() 
	{
		return secondFavoriteLanguage;
	}

	public void setSecondFavoriteLanguage(String secondFavoriteLanguage) 
	{
		this.secondFavoriteLanguage = secondFavoriteLanguage;
	}

	public boolean isExpert() {
		return isExpert;
	}

	public void setExpert(boolean isExpert) 
	{
		this.isExpert = isExpert;
	}

	public boolean isLiar() {
		return isLiar;
	}

	public void setLiar(boolean isLiar) {
		this.isLiar = isLiar;
	}

	public List< SelectItem > getAvailableLanguages()
	{
		return( LanguageUtils.languageList() );
	}
	
	public List< String > getLanguagesToStudy()
	{
		return( languagesToStudy );
	}
	
	public String showTrainingPlan()
	{
		int numLanguagesToStudy;
		
		if( isExpert )
		{
			numLanguagesToStudy = 4;
		}
		else
		{
			numLanguagesToStudy = 2;
		}
		
		if( isLiar )
		{
			return( "liar" );
		}
		else
		{
			languagesToStudy = LanguageUtils.randomLanguages( numLanguagesToStudy );
			
			return( "study-plan");
		}
	}
}
